package org.budo.sms.service.jumeng;

import java.util.Map;

import org.budo.support.http.client.Request;
import org.budo.support.http.client.Response;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@ToString
@Getter
@Setter
@Slf4j
public class BudoJumengSmsServiceImpl implements BudoJumengSmsService {
    private static final String API_URL = "http://smsjm.jxtebie.com/sms/submit";

    private String spid; // 企业帐号 企业代码

    private String ac; // 下发接入码

    private String password; // 企业密码

    @Override
    public String sendSms(String to, String template, Map<String, Object> parameters) {
        Request request = new Request();
        request.setUrl(API_URL);
        request.setMethod(Request.POST);

        request.setField("spid", this.getSpid());
        request.setField("ac", this.getAc());
        request.setField("password", this.getPassword());

        request.setField("mobiles", to);
        request.setField("content", template);

        Response response = request.execute();

        String responseBody = response.getBody();

        log.info("#27 response=" + response + ", request=" + request);
        return responseBody;
    }
}